/*
模块名称：用户登录

功能描述：
1、审核登录用户身份。
2、确定用户登录科室。

业务逻辑：
1、根据输入的用户代码，在 com_priv_user 和 com_department 提取用户可登录的科室名称。
2、核查用户身份和口令是否有效。
3、在com_siginlog表写入登录信息。

*/

#include "com_re_signin.h"
#include "ui_com_re_signin.h"
#include "pub_var.h"
#include <QDebug>
#include <QMessageBox>
#include <QKeyEvent>
#include <QSettings>
#include <QHostInfo>

Com_re_signin::Com_re_signin(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Com_re_signin)
{
    ui->setupUi(this);

    qrm = new QSqlQuery(pub::db_m);
    qro = new QSqlQuery(pub::db_o);

    ui->leUserCode->setText(pub::usr_code);

    ui->cbDepartment->clear();

    qrm->exec("select role_dept from com_privileges "
              " where type = 'dept' "
              " and code = '" + pub::usr_code + "' order by role_dept");

    ui->cbDepartment->clear();

    while(qrm->next())
    {
        ui->cbDepartment->addItem(qrm->value(0).toString());
    }

    ui->cbDepartment->setCurrentIndex(0);

    //接收默认事件的按钮不显示
    ui->pushButton->setVisible(false);

}

Com_re_signin::~Com_re_signin()
{
    delete ui;
}

void Com_re_signin::on_pbOk_clicked()
{
    //设置本机工作参数

    QFont f = ui->label->font();
    QString sty = "color: blue;font-size: " + QString::number(f.pointSize() * 1.5)+"pt;";

    qro->exec("select si_code,jszc,zyfw from com_doctor_compare where empl_code = '"+pub::usr_code+"'");
    if(qro->next())
    {
        pub::dr_codg = qro->value(0).toString();//医保医师代码
        pub::dr_profttl = qro->value(1).toString(); //	医师职称	 字典表
        pub::dr_duty_range = qro->value(2).toString(); //执业范围
    }

    pub::dp_name = ui->cbDepartment->currentText();
    qro->exec("select dept_code from com_department where dept_name = '"
              + pub::dp_name + "'");
    qro->next();
    pub::dp_code = qro->value(0).toString();

    re_signin();
    this->close();

}

void Com_re_signin::on_pbCancel_clicked()
{
    this->close();
}

void Com_re_signin::closeEvent(QCloseEvent *event)
{
    Q_UNUSED(event);
    //QSettings setIni("clin.ini", QSettings::IniFormat);
    //setIni.setValue("windowState/re_singin", QVariant(this->geometry()));

    //emit destroyW( "Com_re_signin" );

}
